package com.doge.walknovel.business.home.discover

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.walknovel.api.model.BannerInfo
import com.doge.walknovel.api.model.NovelInfo
import com.doge.walknovel.api.model.StrategyInfo
import com.doge.walknovel.business.home.discover.viewholders.*
import com.doge.walknovel.core.base.adapters.BasePagedAdapter

const val BANNER = "banner"
const val STRATEGY_MORE = "strategyMore"
const val BOOK_CLICKED = "bookClicked"

class DiscoverAdapter : BasePagedAdapter() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return when (viewType) {
            ItemType.Banner -> DiscoverBannerViewHolder(parent, callback)
            ItemType.Strategy -> DiscoverStrategyViewHolder(parent, callback)
            ItemType.GridContent -> DiscoverGridViewHolder(parent, callback)
            ItemType.GridRankContent -> DiscoverGridViewHolder(parent, callback)
            ItemType.LinearContent -> DiscoverLinearViewHolder(parent, callback)
            else -> super.onCreateViewHolder(parent, viewType)
        }
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val item = getItem(position)
        when (holder) {
            is DiscoverBannerViewHolder -> item?.data<List<BannerInfo>>()?.let { holder.bind(it) }
            is DiscoverStrategyViewHolder -> item?.data<StrategyInfo>()?.let { holder.bind(it) }
            is DiscoverGridViewHolder -> item?.data<NovelInfo>()?.let { holder.bind(it) }
            is DiscoverGridRankViewHolder -> item?.data<NovelInfo>()?.let { holder.bind(it, position) }
            is DiscoverLinearViewHolder -> item?.data<NovelInfo>()?.let { holder.bind(it) }
        }
    }
}
